home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_psutils.idb / usr / freeware / bin / fixmacps.z / fixmacps
Encoding:
Text File  |  1999-07-16  |  2.2 KB  |  98 lines

  1. #!/usr/freeware/bin/perl
  2. eval 'exec perl -S $0 "$@"'
  3.     if $running_under_some_shell;
  4.  
  5. # fixmacps: swap to sanitised appledict
  6. #
  7. # Copyright (C) Angus J. C. Duggan 1991-1995
  8. # See file LICENSE for details.
  9.  
  10. $line = 0;            # keep line count
  11. $dir = "/xlv1/freeware/1999.Aug/psutils/1.17-root/usr/freeware/share/psutils";
  12. $prefix = "md";
  13. $default = "md71_0.ps";
  14.  
  15. while ($_ = shift(@ARGV)) {
  16.    if (/^-d(ir)?$/)   { $dir = shift(@ARGV); }
  17.    elsif (/^-n(ame)?$/)   { $prefix = shift(@ARGV); }
  18.    else {
  19.       unshift(@ARGV, $_);
  20.       last;
  21.    }
  22. }
  23.  
  24. %fonts = ();
  25. $nesting = 0;
  26.  
  27. while (<>) {
  28.    if (/^%!/) {
  29.       if (! $line) {
  30.      print;
  31.       }
  32.    } elsif (/^%%(Begin|Include)ProcSet: "?\(AppleDict md\)"? ([0-9]+) ([0-9]+)$/) {
  33.       local($inc, $mdv, $mdr) = ($1, $2, $3);
  34.       if (open(SANE, "<$dir/$prefix${mdv}_$mdr.ps") ||
  35.       open(SANE, "<$dir/$default")) {
  36.      $sane = <SANE>;
  37.      local($snv, $snr) =
  38.         $sane =~ /^%%BeginProcSet: \(AppleDict md\) ([0-9]+) ([0-9]+)$/;
  39.      if ($mdv == $snv && $mdr == $snr) {
  40.          if ( $inc eq "Include" ) {
  41.          print STDERR "Inserting ProcSet \"(AppleDict md)\" $snv $snr\n";
  42.          print $sane;
  43.          while(<SANE>) {
  44.              print;
  45.          }
  46.          close(SANE);
  47.          }
  48.          else {
  49.          print STDERR "Substituting ProcSet \"(AppleDict md)\" $snv $snr\n";
  50.          $ignore = 1;
  51.          }
  52.      } else {
  53.         print STDERR "Unrecognised AppleDict version $mdv $mdr\n";
  54.         print "%!\n" if !$line;
  55.         print;
  56.      }
  57.       } else {
  58.      print STDERR "Can't find sanitised AppleDict\n";
  59.      print "%!\n" if !$line;
  60.      print;
  61.       }
  62.    } elsif (/^%%EndProcSet/) {
  63.       if ($ignore) {
  64.      $ignore = 0;
  65.      print "%!\n" if !$line;
  66.      print $sane;
  67.      while(<SANE>) {
  68.         print;
  69.      }
  70.      close(SANE);
  71.       } else {
  72.      print "%!\n" if !$line;
  73.      print;
  74.       }
  75.    } elsif (/^%%Page:/ && $nesting == 0) {
  76.       print $_;
  77.       print values(%fonts);
  78.    } elsif (/^%%BeginDocument/ || /^%%BeginBinary/ || /^%%BeginFile/) {
  79.       print $_;
  80.       $nesting++;
  81.    } elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
  82.       print $_;
  83.       $nesting--;
  84.    } else {
  85.       if (! $ignore) {
  86.      if (/^\{\}mark .*rf$/) {
  87.         $fonts{$_} = $_;
  88.         print;
  89.      } else {
  90.         print "%!\n" if !$line;
  91.         print;
  92.      }
  93.       }
  94.    }
  95.    $line++;
  96. }
  97.  
  98.